package com.supcon.exchangedata.repository.slave1;

import com.supcon.exchangedata.pojo.entity.oracle.StatistOtherParametersDay;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: yangbin
 * @Date: 2022/03/18/9:36
 * @Description:
 */
public interface SlaveOneStatistOtherParametersDayRepository extends JpaRepository<StatistOtherParametersDay, Long> {

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(nativeQuery = true, value = "select * from STATIST_OTHER_PARAMETERS_DAY  where DAY_OF_MONTH_KEY >= ?1 and DAY_OF_MONTH_KEY <= ?2 and OBJ_ID is not null and TYPE is not null and DAY_OF_MONTH_KEY is not null and IN_AVG_VALUE  is not null AND (TYPE LIKE '1%' OR TYPE LIKE '2%' OR TYPE LIKE '3%' OR  TYPE LIKE '5%')  order by DAY_OF_MONTH_KEY desc")
    List<StatistOtherParametersDay> findAllByCondition(LocalDateTime startTime, LocalDateTime endTime);
    StatistOtherParametersDay findTopByObjIdAndTypeOrderByDayOfMonthKeyDesc(Long objId, Long type);

    List<StatistOtherParametersDay> findAllByObjIdAndTypeAndInAvgValueIsNotNullAndDayOfMonthKeyBetween(Long objId,Long type,LocalDateTime startTime,LocalDateTime endTime);

    StatistOtherParametersDay findDistinctByDayOfMonthKeyAndObjIdAndType(LocalDateTime dayOfMonthKey, Long objId, Long type);

    List<StatistOtherParametersDay> findAllByObjIdAndTypeAndTypeIsNotNullAndObjIdIsNotNullAndDayOfMonthKeyIsNotNullAndInAvgValueIsNotNullOrderByDayOfMonthKeyDesc(Long objId, Long type);
}
